/** * 项目一户式预览页面 */
<template>
  <div>
    <FpProjYhsPanel v-bind="options" v-if="validatePass" />
    <span v-else>{{ validateMessage }}</span>
  </div>
</template>

<script setup name="ProjectYhsPreviewView">
import XEUtils from 'xe-utils';
import { NextLoading } from '/@/utils/loading';
import {onMounted } from 'vue';

import { FormPojo } from '@fp'
import { FpProjYhsPanel } from '@fp/panels'

// ----- 路由相关操作
// 当前路由
const route = useRoute();
const query = route.query;

// 获取一户式配置
const options = ref({});
const validatePass = ref(false);
const validateMessage = ref('');
const setOptions = () => {
  let config = {};
  // ---------- 处理proId
  // 校验proId
  if (!query.hasOwnProperty('proId')) {
    validateMessage.value = 'proId参数不存在，请确认！';
    return;
  }
  const { proId: queryProId } = query
  if (!queryProId) {
    validateMessage.value = 'proId参数内容不能为空，请确认！';
    return;
  }
  // 获取proId
  let proId = ''
  // 如果是数组
  if (XEUtils.isArray(queryProId)) {
    proId = queryProId.filter(item => !XEUtils.isEmpty(item))[0]
  } else {
    proId = queryProId
  }
  config['proId'] = proId

  // ---------- 处理applyId
  let applyId = ''
  const { applyId: queryApplyId } = query
  if (query.hasOwnProperty('applyId')) {
    if (queryApplyId) {
      if (XEUtils.isArray(queryApplyId)) {
        applyId = queryApplyId.filter(item => !XEUtils.isEmpty(item))[0]
      } else {
        applyId = queryApplyId
      }
    }
  }
  config['applyId'] = applyId

  // ---------- 处理表单类型
  let yhsFormType = ''
  if (query.hasOwnProperty('type')) {
    const { type } = query
    if (XEUtils.isArray(type)) {
      yhsFormType = type.filter(item => !XEUtils.isEmpty(item))[0]
    } else {
      yhsFormType = type
    }
  } else if (query.hasOwnProperty('bondTypeCode')) {
    const { bondTypeCode } = query
    if (XEUtils.isArray(bondTypeCode)) {
      let bondTypeCode = bondTypeCode.filter(item => !XEUtils.isEmpty(item))[0]
      yhsFormType = (bondTypeCode == '1') ? 'GE' : 'SP'
    } else {
      yhsFormType = ''
    }
  }

  if (!yhsFormType) {
    validateMessage.value = 'type参数不存在或bondTypeCode参数不存在，请确认！';
    return;
  }
  // 校验是否存在对应类型的Form表单
  const formConfig = FormPojo.FormYhs[yhsFormType];
  if (!formConfig) {
    validateMessage.value = '对应的表单配置不存在，请确认！';
    return;
  }
  config = { ...config, ...formConfig };
  if (['AT', 'FD'].includes(yhsFormType)) {
    config['defaultTabActiveName'] = 'jbxx';
  }
  validatePass.value = true;
  options.value = { ...config };
};

// 页面加载时
onMounted(() => {
  NextLoading.done();
});

setOptions();
</script>

<style lang="scss" scoped></style>
